package system.company.base.Objects;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import system.company.actor.Ordinary_Staff.BaseHibernateDAO;

/**
 * A data access object (DAO) providing persistence and search support for
 * Object_CompanyNotice entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see system.company.base.Objects.Object_CompanyNotice
 * @author MyEclipse Persistence Tools
 */

public class Object_CompanyNoticeDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory
			.getLog(Object_CompanyNoticeDAO.class);
	// property constants
	public static final String TITLE = "title";
	public static final String CONTENT = "content";
	public static final String DEPARTMENT = "department";
	public static final String TIME = "time";
	public static final String VISITED = "visited";

	public void save(Object_CompanyNotice transientInstance) {
		log.debug("saving Object_CompanyNotice instance");
		try {
			Transaction tran = getSession().getTransaction();
			tran.begin();
			getSession().save(transientInstance);
			tran.commit();
			getSession().clear();
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Object_CompanyNotice persistentInstance) {
		log.debug("deleting Object_CompanyNotice instance");
		try {
			Transaction tran = getSession().getTransaction();
			tran.begin();
			getSession().delete(persistentInstance);
			tran.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Object_CompanyNotice findById(java.lang.Integer id) {
		log.debug("getting Object_CompanyNotice instance with id: " + id);
		try {
			Object_CompanyNotice instance = (Object_CompanyNotice) getSession()
					.get("system.company.base.Objects.Object_CompanyNotice", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Object_CompanyNotice instance) {
		log.debug("finding Object_CompanyNotice instance by example");
		try {
			List results = getSession().createCriteria(
					"system.company.base.Objects.Object_CompanyNotice").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Object_CompanyNotice instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Object_CompanyNotice as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}

	public List findByContent(Object content) {
		return findByProperty(CONTENT, content);
	}

	public List findByDepartment(Object department) {
		return findByProperty(DEPARTMENT, department);
	}

	public List findByTime(Object time) {
		return findByProperty(TIME, time);
	}

	public List findByVisited(Object visited) {
		return findByProperty(VISITED, visited);
	}

	public List findAll() {
		log.debug("finding all Object_CompanyNotice instances");
		try {
			String queryString = "from Object_CompanyNotice";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Object_CompanyNotice merge(Object_CompanyNotice detachedInstance) {
		log.debug("merging Object_CompanyNotice instance");
		try {
			Object_CompanyNotice result = (Object_CompanyNotice) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Object_CompanyNotice instance) {
		log.debug("attaching dirty Object_CompanyNotice instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Object_CompanyNotice instance) {
		log.debug("attaching clean Object_CompanyNotice instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}